package com.yuda.tools.miscellaneous.mapper;

import com.yuda.tools.miscellaneous.dto.PaperCount;
import com.yuda.tools.miscellaneous.dto.PaperMachined;
import com.yuda.tools.miscellaneous.dto.SpartaExamConfig;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PaperCountMapper {

    /**
     * 查询印量表
     */
    List<PaperCount> listPaperCount(@Param("examUuid") String examUuid, @Param("tableSuffix") String tableSuffix);

    @Select("SELECT a.amount_json from bm_school_exam a , bm_school_primary b where a.school_primary_id = b.id\n" +
            "and a.exam_uuid = #{examUuid} and a.amount_json is not null and b.school_id = #{schoolId}")
    String getAmountJson(@Param("examUuid") String examUuid, @Param("schoolId") String schoolId);

    @Select("SELECT 1 type,a.school_id schoolId,b.amount_json amountJson,c.province_name provinceName,c.`name`,e.paper_type paperType\n" +
            "FROM bm_school_primary a\n" +
            "LEFT JOIN bm_school_exam b ON a.id = b.school_primary_id\n" +
            "LEFT JOIN sparta_school c on c.id = a.school_id\n" +
            "LEFT JOIN (SELECT province_name,CASE WHEN gaokao_type = 1 THEN '全国一卷' WHEN gaokao_type = 2 THEN '全国二卷' ELSE '改革卷' END paper_type FROM sparta_gk_province_type WHERE grade_id = 3)e ON c.province_name = e.province_name\n" +
            "WHERE b.exam_uuid = #{examUuid} AND b.amount_json IS NOT NULL\n" +
            "AND a.school_id NOT IN(SELECT school_id FROM excel_student2019 WHERE exam_uuid = #{examUuid} GROUP BY school_id)  and b.status_join =1")
    List<PaperMachined> manufactured(String examUuid);

    @Select("SELECT exam_uuid examUuid,`name` from sparta_exam_config where name like '%诊断%' and `desc` like CONCAT('%',YEAR(now()),'%')\n")
    List<SpartaExamConfig> listExamUuids();
}
